package top.zhangjianyong.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.zhangjianyong.blog.enums.RespCode;
import top.zhangjianyong.blog.entity.po.BlogDetail;
import top.zhangjianyong.blog.exception.ApiException;
import top.zhangjianyong.blog.mapper.BlogDetailMapper;
import top.zhangjianyong.blog.service.BlogDetailService;

/**
 * 博客详情
 *
 * @author zhangjianyong
 * @since 2024/8/1 上午9:16
 */
@Service
public class BlogDetailServiceImpl extends ServiceImpl<BlogDetailMapper, BlogDetail>
    implements BlogDetailService {
  @Override
  public BlogDetail saveOrUpdate(Long id, String mkContent) {
    BlogDetail blogDetail = new BlogDetail();
    blogDetail.setId(id);
    blogDetail.setMkContent(mkContent);
    boolean flag = null == blogDetail.getId() ? save(blogDetail) : updateById(blogDetail);
    if (!flag) throw new ApiException(RespCode.BLOG_DETAIL_SAVE_OR_UPDATE_ERROR);
    return blogDetail;
  }
}
